﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;
public partial class HR_Modify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            Store1Bind();
        }
    }
    protected void Store1Bind()
    {
        Query q = new Query(VwStaffHrStep1.Schema);
        q.AddWhere("enteringuserid", Cookies.getCookies("cuid"));
        q.AddWhere("adept_master_status", 2);
        q.SetSelectList("id,ed_username,ed_deptname,adept_master_status,dept_master_status,boss_status,intime,guid");
        q.ORDER_BY("id desc");
        
        Store1.DataSource = q.ExecuteDataSet();
        Store1.DataBind();
    }
    protected void DeleteRow(object s, AjaxEventArgs e)
    {
        string id = e.ExtraParams["id"].ToString();
        
        CxStaffHr.Delete("id", id);
        Err.Warning("删除成功！", MessageBox.Icon.NONE);
        Store1.DataBind();
        Clear();
        
    }
    protected void Store1_OnRefreshData(object s, StoreRefreshDataEventArgs e)
    {
        Store1Bind();
    }
    [AjaxMethod]
    protected void RowSelect(object s, AjaxEventArgs e)
    {
        string id = e.ExtraParams["id"].ToString();
       
       
        Query q = new Query(VwStaffHrStep1.Schema);
        q.AddWhere("id", id);
        IDataReader dr = q.ExecuteReader();
        if (dr.Read())
        {
            tfhiddenid.Value = id;
            tfhiddenguid.Value = dr["guid"].ToString();
            if (dr["talktime"].ToString() != "") { TfTalkTime.Value = dr["talktime"].ToString(); }
            TfTalkContent.Text = dr["talkcontent"].ToString();
            if (dr["punish_party_time"].ToString() != "") { TfPunish_party_time.Value = dr["punish_party_time"].ToString(); }
            TfPunish_party_type.SetInitValue(dr["punish_party_type"].ToString());
            TfPunish_party_reason.Text=dr["punish_party_reason"].ToString();
            if (dr["punish_penal_time"].ToString() != "") { TfPunish_penal_time.Value = dr["punish_penal_time"].ToString(); }
            TfPunish_penal_type.SetInitValue(dr["punish_penal_type"].ToString());
            TfPunish_penal_reason.Text = dr["punish_penal_reason"].ToString();
            TfParty_Problem.Text = dr["party_problem"].ToString();
            TfOther_Problem.Text = dr["other_problem"].ToString();
            tflbusername.Text = dr["ed_username"].ToString();
            TfDeptName.Text = dr["ed_deptname"].ToString();
            TfaDept_master_entering_time.Text = dr["adept_master_entering_time"].ToString();
            TfaDept_master_remark.Text = dr["adept_master_remark"].ToString();
            TfaDept_MasterID.SetInitValue(dr["adept_masterid"].ToString());
            switch (dr["adept_master_status"].ToString())
            {
                case "0":
                    TfaDept_master_status.Text = "未审核";
                    break;
                case "1":
                    TfaDept_master_status.Text = "同意";
                    break;
                case "2":
                    TfaDept_master_status.Text = "退回";
                    break;
            }
        }
    }
    protected void SubReportAdd(object s, AjaxEventArgs e)
    {
        if (tfhiddenid.Value == "") { Err.Warning("请选择一份档案！", MessageBox.Icon.WARNING); return; }
        CxStaffHr cx = new CxStaffHr("id",tfhiddenid.Value);
        if (TfTalkTime.Value.ToString() != "0001/1/1 0:00:00")
        {
            cx.TalkTime = DateTime.Parse(TfTalkTime.Value.ToString());
        }
        cx.TalkContent = TfTalkContent.Text;
        if (TfPunish_party_time.Value.ToString() != "0001/1/1 0:00:00")
        {
            cx.PunishPartyTime = DateTime.Parse(TfPunish_party_time.Value.ToString());
        }
        cx.PunishPartyType = TfPunish_party_type.SelectedItem.Value.ToString();
        cx.PunishPartyReason = TfPunish_party_reason.Text;
        if (TfPunish_penal_time.Value.ToString() != "0001/1/1 0:00:00")
        {
            cx.PunishPenalTime = DateTime.Parse(TfPunish_penal_time.Value.ToString());
        }
        cx.PunishPenalType = TfPunish_penal_type.SelectedItem.Value.ToString();
        cx.PunishPenalReason = TfPunish_penal_reason.Text;
        cx.PartyProblem = TfParty_Problem.Text;
        cx.OtherProblem = TfOther_Problem.Text;
        cx.ADeptMasterStatus = 0;
        cx.Save();

        CXFileUpload.Del(tfhiddenguid.Value.ToString());
        CXFileUpload.Sv(tffileupload, new Guid(tfhiddenguid.Value.ToString()));

        Err.Warning("修改提交成功，请等待审核！", MessageBox.Icon.NONE);

        Clear();
    }
    protected void Clear()
    {
        TfTalkTime.Clear();
        TfTalkContent.Clear();
        TfPunish_penal_type.Reset();
        TfPunish_penal_time.Clear();
        TfPunish_penal_reason.Clear();
        TfPunish_party_type.Reset();
        TfPunish_party_time.Clear();
        TfPunish_party_reason.Clear();
        TfParty_Problem.Clear();
        TfOther_Problem.Clear();
        tflbusername.Text = "";
        tfhiddenid.Clear();
        TfDeptName.Text = "";
        TfaDept_MasterID.Reset();
        TfaDept_master_status.Text = "";
        TfaDept_master_remark.Text = "";
        TfaDept_master_entering_time.Text = "";
        tffileupload.Text = "";        
    }
}
